﻿Imports System.Threading
Imports System.IO
Imports System.Windows.Forms.Menu

Public Class frmmain
    Dim Strsql As String = ""
    Dim Mysql1 As New ClsSQLhelper
    Public mSpk As AgentObjects.IAgentCtlCharacter
    Public User As String
    Public UserFullname As String
    Private Sub LogOutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LogOutToolStripMenuItem.Click
        Strsql = "delete onlineuser where onlineid ='" & My.Settings.CurrentOnlineid & "'"
        Mysql1.MySQLExecute(Strsql)

        My.Settings.Currentuser = ""
        My.Settings.CurrentOnlineid = ""
        My.Settings.CurrentuserGroup = 0
        frmchangelogin.ShowDialog()
    End Sub

    Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
        Me.Dispose()
        frmlogin.Dispose()
    End Sub

    Private Sub OnlineUserToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OnlineUserToolStripMenuItem.Click
        With frmOnlineuser
            .MdiParent = Me
            .Show()
        End With
    End Sub

    Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
        With frmproductlist
            .MdiParent = Me
            .Show()
        End With
    End Sub

    Private Sub ToolStripButton5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton5.Click
        With frmPROrder
            .MdiParent = Me
            .Show()
        End With
    End Sub

    Private Sub ToolStripButton8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton8.Click
        frmPoOrder.MdiParent = Me
        frmPoOrder.Show()
    End Sub

    Private Sub ToolStripButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton2.Click
        frmReceiveOrder.MdiParent = Me
        frmReceiveOrder.Show()

    End Sub

    Private Sub ToolStripButton6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton6.Click
        If My.Settings.CurrentuserGroup <> 1 Then
            MsgBox("คุณไม่ได้รับสิทธิ์ในการเข้าถึงระบบงานนี้", MsgBoxStyle.Exclamation, "กรุณาติดต่อผู้ดูแลระบบ")
            Exit Sub
        End If
        With frmsite
            .MdiParent = Me

            .Show()
        End With
    End Sub

    Private Sub ToolStripButton7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton7.Click
        If My.Settings.CurrentuserGroup = 3 Then
            MsgBox("คุณไม่ได้รับสิทธิ์ในการเข้าถึงระบบงานนี้", MsgBoxStyle.Exclamation, "กรุณาติดต่อผู้ดูแลระบบ")
            Exit Sub
        End If
        With frmuser
            .MdiParent = Me
            .Show()
        End With
    End Sub

    Private Sub ItemInformationToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ItemInformationToolStripMenuItem.Click
        frmproductdetail.MdiParent = Me
        frmproductdetail.Show()
    End Sub



    Private Sub ReceiveToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ReceiveToolStripMenuItem.Click
        frmReceivedetail.MdiParent = Me
        frmReceivedetail.Show()
    End Sub

    Private Sub SystemSettingToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SystemSettingToolStripMenuItem.Click
        If My.Settings.CurrentuserGroup = 3 Then
            MsgBox("คุณไม่ได้รับสิทธิ์ในการเข้าถึงระบบงานนี้", MsgBoxStyle.Exclamation, "กรุณาติดต่อผู้ดูแลระบบ")
            Exit Sub
        End If
        MnSetting.Visible = True
    End Sub

    Private Sub SQLTracesToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SQLTracesToolStripMenuItem.Click
        If My.Settings.CurrentuserGroup <> 1 Then
            MsgBox("คุณไม่ได้รับสิทธิ์ในการเข้าถึงระบบงานนี้", MsgBoxStyle.Exclamation, "กรุณาติดต่อผู้ดูแลระบบ")
            Exit Sub
        End If
        frmSQLTrace.Show()
    End Sub

    Private Sub SQLQueryToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SQLQueryToolStripMenuItem.Click
        If My.Settings.CurrentuserGroup <> 1 Then
            MsgBox("คุณไม่ได้รับสิทธิ์ในการเข้าถึงระบบงานนี้", MsgBoxStyle.Exclamation, "กรุณาติดต่อผู้ดูแลระบบ")
            Exit Sub
        End If
        FrmSQLQuery.Show()
    End Sub

    Private Sub BackupDatabaseToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BackupDatabaseToolStripMenuItem.Click
        With frmBackupDB
            .MdiParent = Me
            .Show()
        End With
    End Sub

    Private Sub AboutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutToolStripMenuItem.Click
        AboutBox1.Show()
    End Sub

    Private Sub AssistantToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AssistantToolStripMenuItem.Click
        mSpk.Show(0)
    End Sub

    Private Sub AssistantHelpToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AssistantHelpToolStripMenuItem.Click
        Form1.MdiParent = Me
        Form1.Show()
    End Sub

    Private Sub frmmain_Disposed(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Disposed

        For i As Integer = My.Application.OpenForms.Count - 1 To 0 Step -1
            If My.Application.OpenForms.Item(i) IsNot Me Then
                My.Application.OpenForms.Item(i).Close()
            End If
        Next i
    End Sub

    Private Sub frmmain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        My.Settings.Currentuser = frmlogin.TxtUser.Text
        My.Settings.CurrentSite = frmlogin.CboSite.SelectedValue
        My.Settings.CurrentIPaddress = Pn_Framework.Get_IPAddress
        My.Settings.CurrentComputer = Pn_Framework.Get_Computername
        My.Settings.CurrentOnlineid = frmlogin.StrCurrGUID
        frmlogin.Hide()
        'Me.TxtUser.Text = ClsSQLhelper.MySQLUser
        'Me.TxtPassword.Text = ClsSQLhelper.MySQLPassword
        'Me.TxtPort.Text = ClsSQLhelper.MySQLPort
        'Me.TxtHost.Text = ClsSQLhelper.MySQLServer

        TSServer.Text = "Server : " & ClsSQLhelper.MySQLServer
        Me.TSIP.Text = "  IP : " & Pn_Framework.Get_IPAddress
        Me.TSVersion.Text = "  WHIS V. : " & Pn_Framework.Get_PublishVesrion
        ' 
        'If File.Exists("C:\WINDOWS\msagent\chars\merlin.acs") = False Then
        '    MsgBox("Need to download(merlin) on http://www.microsoft.com/downloads/details.aspx?FamilyID=FEE1DADD-2F23-41D0-8A81-2AFFD74C0AA5&displayLang=en", MsgBoxStyle.OkCancel, "กรุณา Download")
        '    Exit Sub
        'End If

        'AxAgent1.Characters.Load("merlin", "C:\WINDOWS\msagent\chars\merlin.acs")
        'mSpk = AxAgent1.Characters("merlin")
        'mSpk.MoveTo(Convert.ToInt16(Me.Width - 150), Convert.ToInt16(Me.Height - 150))
        'mSpk.Show(0)
        ''Stop the previous action to start new one
        'mSpk.Stop()
        'mSpk.Play("Greet")
        'mSpk.Speak("Howdy " & My.Settings.Currentuser)
        ''Speak the text
        'mSpk.SoundEffectsOn = True
        ''Turn to rest position
        'mSpk.Play("RestPose")
        ''Load_BasicData()
    End Sub
    'Sub Load_BasicData()
    '    Dim DS_System As New DS_whis
    '    Strsql = "Select * from site where active = 1  order by site "
    '    DS_System = Mysql1.GetMYSQLDataset(Strsql, DS_System, "site")
    '    MsgBox(DS_System.Tables("site").Rows.Count)
    'End Sub
    Private Sub ToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem1.Click
        With frmsite
            .MdiParent = Me
            .WindowState = FormWindowState.Maximized
            .Show()
        End With
    End Sub

    Private Sub mmsection_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mmsection.Click
        With frmsection
            .MdiParent = Me
            .WindowState = FormWindowState.Maximized
            .Show()
        End With
    End Sub

    Private Sub mmCategory_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mmCategory.Click
        With frmcategory
            .MdiParent = Me
            .WindowState = FormWindowState.Maximized
            .Show()
        End With
    End Sub

   

    Private Sub mmManufac_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mmManufac.Click
        With frmmanufactur
            .MdiParent = Me
            .WindowState = FormWindowState.Maximized
            .Show()
        End With
    End Sub

    Private Sub mmVendor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mmVendor.Click
        With FrmVendor
            .MdiParent = Me
            .WindowState = FormWindowState.Maximized
            .Show()
        End With
    End Sub

    Private Sub mmuser_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mmuser.Click
        With frmuser
            .MdiParent = Me
            .WindowState = FormWindowState.Maximized
            .Show()
        End With
    End Sub

  

    Private Sub ปดToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ปดToolStripMenuItem.Click
        MnSetting.Visible = False
    End Sub

    Private Sub MnEndUserReport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MnEndUserReport.Click
        With frmreportsmanagent
            .MdiParent = Me
            .WindowState = FormWindowState.Maximized
            .Show()
        End With
    End Sub

    Private Sub MnEncrypt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MnEncrypt.Click
        With frmEncrypt
            .MdiParent = Me
            .Show()
        End With
    End Sub

    Private Sub XMLGeneraterToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles XMLGeneraterToolStripMenuItem.Click
        With DlgXMLGenerater
            .MdiParent = Me
            .Show()
        End With

    End Sub


    Private Sub BarcodeToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BarcodeToolStripMenuItem.Click
        With frmRptBarcodeList
            .MdiParent = Me
            .Show()
        End With
    End Sub

    Private Sub ToolStripButton4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton4.Click
        With frmdrawOrder
            .MdiParent = Me
            .Show()
        End With
    End Sub
    Private Sub SupplyListToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SupplyListToolStripMenuItem.Click
        With frmSupplyManagement
            .MdiParent = Me
            .WindowState = FormWindowState.Maximized
            .Show()
        End With
    End Sub

    Private Sub SiteToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SiteToolStripMenuItem.Click
        With frmStocklist
            .MdiParent = Me
            .WindowState = FormWindowState.Maximized
            .Show()
        End With
    End Sub

    Private Sub GroupToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GroupToolStripMenuItem.Click
        With frmproductgrouplist
            .MdiParent = Me
            .WindowState = FormWindowState.Maximized
            .Show()
        End With
    End Sub
End Class